package zy928;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

import XmlDemo.Product;

public class Zy1 {
	public static void main(String[] args) throws DocumentException {
		SAXReader reader = new SAXReader();
		Document doc = reader.read(new File("products.xml"));
		List<Element> list = (List<Element>) doc.selectNodes("shop/product");
		List<Product> list1 = new ArrayList();
		for (Element e : list) {
			String factoryadd = e.attributeValue("factoryadd");
			long itemno = Long.parseLong(e.selectSingleNode("itemno").getText());
			String name = e.selectSingleNode("name").getText();
			String unit = e.selectSingleNode("unit").getText();
			double price = Double.parseDouble(e.selectSingleNode("price").getText());
			int stockcount = Integer.parseInt(e.selectSingleNode("stockcount").getText());
			boolean discount = Boolean.parseBoolean(e.attributeValue("discount"));
			Product p = new Product(itemno, factoryadd, name, unit, price, stockcount, discount);
			list1.add(p);
		}
		for (Product s : list1) {
			System.out.println(s);
		}
	}
}
